home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hardcore Visual Basic 5.0 (2nd Edition)
/
Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso
/
Code
/
Goodies
/
SYSTEM~1
/
SYSCOL~2.FRM
< prev
next >
Wrap
Text File
|
1997-06-09
|
8KB
|
246 lines
VERSION 5.00
Begin VB.Form SysColorPal
AutoRedraw = -1 'True
BorderStyle = 3 'Fixed Dialog
ClientHeight = 780
ClientLeft = 4230
ClientTop = 4395
ClientWidth = 1560
ControlBox = 0 'False
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
PaletteMode = 1 'UseZOrder
ScaleHeight = 52
ScaleMode = 3 'Pixel
ScaleWidth = 104
ShowInTaskbar = 0 'False
Begin VB.VScrollBar VScroll1
Height = 690
LargeChange = 9
Left = 0
Max = 18
TabIndex = 0
Top = 0
Width = 270
End
End
Attribute VB_Name = "SysColorPal"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'System Color Palette 1.0 - (27 Windows System Colors)
'Created by Randy Russell - June 1997
'Created using Microsoft Visual Basic 5.0
'If the user clicks or double clicks any color then the
' SelectedColor and SelectedColorName properties are set
' and the palette is unloaded.
'A right click sets SelectedColorName to "" and unloads the palette.
'declare program variables
Dim SysColorNames(26) As String 'array for color names
Dim SysColors(26) As Long 'array for color values
Dim CurTop As Integer 'scroll position
Dim iColor As Integer 'default, cur selected color
Dim CurHighLight As Integer 'currently highlighted color
Dim MyBackColor As Long 'palette background color
Public SelectedColor As Long 'user selected color value
Public SelectedColorName As String 'user selected color name
Const CellDim = 13 'size of color boxes
Const OffsetY = 16 'distance between rows
Const DefColor = 6 'default color value
Private Sub DrawCell(CellX As Integer, CellY As Integer, CellWidth As Integer, CellHeight As Integer, CellColor As Long)
'plot 3d square and fill with current color
ForeColor = &H808080
Line (CellX, CellY)-(CellX + CellWidth - 1, CellY)
Line (CellX, CellY)-(CellX, CellY + CellHeight - 1)
ForeColor = vbWhite
Line (CellX, CellY + CellHeight - 1)-(CellX + CellWidth, CellY + CellHeight - 1)
Line (CellX + CellWidth - 1, CellY)-(CellX + CellWidth - 1, CellY + CellHeight)
ForeColor = &HC0C0C0
If ForeColor = CellColor Then ForeColor = &HE0E0E0
Line (CellX + 1, CellY + CellHeight - 2)-(CellX + CellWidth - 1, CellY + CellHeight - 2)
Line (CellX + CellWidth - 2, CellY + 1)-(CellX + CellWidth - 2, CellY + CellHeight - 1)
ForeColor = vbBlack
Line (CellX + 1, CellY + 1)-(CellX + 1, CellY + CellHeight - 2)
Line (CellX + 1, CellY + 1)-(CellX + CellWidth - 2, CellY + 1)
ForeColor = CellColor
Line (CellX + 2, CellY + 2)-(CellX + CellWidth - 3, CellY + CellHeight - 3), , BF
End Sub
Private Sub Form_Activate()
'refresh colors and redraw to assure that the system colors
'stored reflect *current* windows system colors
'*un-comment the next two lines if you plan to leave the palette loaded
'GetColorValues
'DrawSysPal CurTop
End Sub
Private Sub Form_DblClick()
'set selection and hide
SelectedColor = SysColors(iColor)
SelectedColorName = SysColorNames(iColor)
Hide
End Sub
Private Sub Form_Load()
'initialize program variables
GetColorValues
MyBackColor = vbButtonFace
CurTop = 0
'set default color values
iColor = DefColor
CurHighLight = iColor
SelectedColor = SysColors(iColor)
SelectedColorName = SysColorNames(iColor)
'set palette size and location
Width = 2345 'optimum so no horz scroll needed
Height = 2270 'setup for 9 visible rows spaced 16 apart + borders
'Move ((frmSysColors.Width - Width) / 2) + frmSysColors.Left, frmSysColors.Top + 4000
VScroll1.Top = 0
VScroll1.Left = 132
VScroll1.Height = 145
VScroll1.Width = 18
BackColor = MyBackColor
'draw palette
DrawSysPal CurTop
End Sub
Private Sub GetColorValues()
'assign system color names
SysColorNames(0) = "3DDKShadow"
SysColorNames(1) = "3DFace"
SysColorNames(2) = "3DHighlight"
SysColorNames(3) = "3DLight"
SysColorNames(4) = "3DShadow"
SysColorNames(5) = "ActiveBorder"
SysColorNames(6) = "ActiveTitleBar"
SysColorNames(7) = "ApplicationWorkspace"
SysColorNames(8) = "ButtonFace"
SysColorNames(9) = "ButtonShadow"
SysColorNames(10) = "ButtonText"
SysColorNames(11) = "Desktop"
SysColorNames(12) = "GrayText"
SysColorNames(13) = "Highlight"
SysColorNames(14) = "HighlightText"
SysColorNames(15) = "InactiveBorder"
SysColorNames(16) = "InactiveCaptionText"
SysColorNames(17) = "InactiveTitleBar"
SysColorNames(18) = "InfoBackground"
SysColorNames(19) = "InfoText"
SysColorNames(20) = "MenuBar"
SysColorNames(21) = "MenuText"
SysColorNames(22) = "ScrollBars"
SysColorNames(23) = "TitleBarText"
SysColorNames(24) = "WindowBackground"
SysColorNames(25) = "WindowFrame"
SysColorNames(26) = "WindowText"
'assign system color values
SysColors(0) = vb3DDKShadow
SysColors(1) = vb3DFace
SysColors(2) = vb3DHighlight
SysColors(3) = vb3DLight
SysColors(4) = vb3DShadow
SysColors(5) = vbActiveBorder
SysColors(6) = vbActiveTitleBar
SysColors(7) = vbApplicationWorkspace
SysColors(8) = vbButtonFace
SysColors(9) = vbButtonShadow
SysColors(10) = vbButtonText
SysColors(11) = vbDesktop
SysColors(12) = vbGrayText
SysColors(13) = vbHighlight
SysColors(14) = vbHighlightText
SysColors(15) = vbInactiveBorder
SysColors(16) = vbInactiveCaptionText
SysColors(17) = vbInactiveTitleBar
SysColors(18) = vbInfoBackground
SysColors(19) = vbInfoText
SysColors(20) = vbMenuBar
SysColors(21) = vbMenuText
SysColors(22) = vbScrollBars
SysColors(23) = vbTitleBarText
SysColors(24) = vbWindowBackground
SysColors(25) = vbWindowFrame
SysColors(26) = vbWindowText
End Sub
Public Sub DrawSysPal(TopIndex As Integer)
'declare local variables
Dim i As Integer
Dim j As Integer
Dim px As Integer
Dim py As Integer
'clear palette and validate top row index
px = 2
py = 1
Cls
If TopIndex > 18 Then TopIndex = 18
If TopIndex < 0 Then TopIndex = 0
CurTop = TopIndex
'plot the 9 visible rows
For i = TopIndex To TopIndex + 8
DrawCell px, py + 1, CellDim, CellDim, SysColors(i)
If CurHighLight = i Then
'draw a filled rect for highlight
Line (px + CellDim + 2, py - 1)-(VScroll1.Left - 5, py + OffsetY - 2), vbHighlight, BF
ForeColor = vbHighlightText
Else
ForeColor = vbWindowText
End If
'position and print color name
CurrentX = px + CellDim + 3
CurrentY = py
Print SysColorNames(i)
'reset position for next row
py = py + OffsetY
px = 2
Next i
'add 3d line to seperate scrollbar
i = VScroll1.Left - 2
Line (i, 0)-(i, ScaleHeight), vb3DShadow
Line (i + 1, 0)-(i + 1, ScaleHeight), vb3DHighlight
Refresh
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim icell As Integer
Dim NewColor As Integer
'if right button clicked then cancel
If Button = 2 Then
SelectedColorName = ""
Hide
Else
'determine selection
icell = Int(Y / OffsetY)
NewColor = CurTop + icell
'if clicked the same color again then repaint
If NewColor <> iColor Then
'reset highlight and repaint
iColor = NewColor
CurHighLight = iColor
DrawSysPal CurTop
End If
'set selection properties
SelectedColor = SysColors(NewColor)
SelectedColorName = SysColorNames(NewColor)
Hide
End If
End Sub
Private Sub VScroll1_Change()
'pass current top row value and repaint
DrawSysPal VScroll1.Value
End Sub